from renren import RenRen
from datetime import datetime
import time
import sys

uname = "wonderfuly@gmail.com"
pwd = "w0nderfu1y"
print "Login..."
rr = RenRen(uname, pwd)
login_success = rr.login()
if login_success:
    print "Login success"
else:
    print "Login failed"
    sys.exit()

fp = open("count_result.txt", "a+")
  
while True:
    try:
        result = rr.getOnlineCount()+ " " + datetime.now().strftime("%Y %m %d %H:%M")
        print result
        fp.write(result + "\n")
        fp.flush()
        time.sleep(60 * 5)
    except:
        print "error, retry"
